package com.hbnu.dao;

import com.hbnu.entity.User;

import java.sql.PreparedStatement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


public class UserDao extends JDBC{

    public List<User> selectUserAll() {
        try(Statement statement=getStatement()){
            String sql= "select user_id,user_name,created_time,logon_time,size,space,is_deleted,fid from users;";
            ResultSet resultSet = statement.executeQuery(sql);
            List<User> list=new ArrayList<>();
            while (resultSet.next()){
                User user=new User();
                user.setUid(resultSet.getString(1));
                user.setName(resultSet.getString(2));
                user.setCreated_time(resultSet.getTimestamp(3).toLocalDateTime());
                user.setLogon_time(resultSet.getTimestamp(4).toLocalDateTime());
                user.setSize(resultSet.getLong(5));
                user.setSpace(resultSet.getLong(6));
                user.setIs_deleted(resultSet.getBoolean(7));
                user.setFid(resultSet.getInt(8));
                list.add(user);
            }
            return list;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
